package jzOffer;

public class Num15 {
    //巧用n&(n-1)
    public int hammingWeight(int n) {
        int count=0;
        while(n!=0){
            count++;
            n=n&n-1;
        }
        return count;
    }
    //逐位检查
//    public int hammingWeight(int n) {
//        int count=0;
//        while(n!=0){
//            count+=n&1;
//            n=n>>>1;
//        }
//        return count;
//    }
}
